package com.geovis.emergency.spd.biz.iflytek.config;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.geovis.emergency.spd.redis.RedisUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.time.Duration;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 科大相关配置信息
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/8/24
 */
public class IflytekConfig {
    public static final String BASE_URL = "https://172.22.17.50:8090";

    public static final String KG_ID ="9b0609162a974aacbc27528c80c83c09";
    /**
     * 图谱CODE
     */
    public static final String GRAPH_NAME = "hnyatp6086";
    /**
     * 预案概念名称
     */
    public static final String PLAN_LABEL = "yjya";
    /**
     * 预案成员单位概念名称
     */
    public static final String DEPT_LABEL = "cydw";

    /**
     * 预案演练
     */
    public static final String DRILL_LABEL = "yayl";


    /**
     * 演练事件
     */
    public static final String EVENT_LABEL = "ylsj";

    /**
     * 事件任务，方案
     */
    public static final String TASK_LABEL = "sjrw";

    /**
     * 行动任务
     */
    public static final String FEEDBACK_LABEL = "sjxd";

    /**
     * 预案职责单位关联
     */
    public static final String PLAN_DEPT_LABEL = "yadwzz";

    /**
     * 演练关联预案
     */
    public static final String DRILL_PLAN_LABEL = "yacsdyl";


    /**
     * 演练关联事件
     */
    public static final String DRILL_EVENT_LABEL = "ylglsj";

    /**
     * 事件关联任务
     */
    public static final String EVENT_TASK_LABEL = "sjzxdrw";
    /**
     * 事件任务 和 任务行动 关联关系
     */
    public static final String TASK_FEEDBACK_LABEL = "rwzxdxd";

    /**
     * 推送实体信息
     */
    public static final String REQUEST_GRAPH_URL = BASE_URL+"/graphApi/api/v1/graph/"+GRAPH_NAME+"/graph/vertex";
    /**
     * 创建关联关系
     */
    public static final String REQUEST_EDGE_URL = BASE_URL+"/graphApi/api/v1/graph/"+GRAPH_NAME+"/graph/edge/batch";
    /**
     * 获取图谱URL
     */
    public static final String GRAPH_URL = BASE_URL+"/graphApi/api/v1/graph/"+GRAPH_NAME+"/graph/visualize/adjacentVertices";

    public static final List<String> IMAGE_LIST = Lists.newArrayList("jpg", "jpeg", "png", "gif", "bmp");

    public static final String UPLOAD_SUCCESS_CODE = "000000";

    public static final int SUCCESS_CODE = 200;

    public static String TOKEN_KEY = "iflytek:token";

    public  static String ACCOUNT = "aimindadmin";
    public static String PASSWORD = "admin2020_";

    public static String AUTH_TOKEN(){
        return RedisUtil.getEx(TOKEN_KEY, Duration.ofHours(20),()->{
            Map<String, Object> map = Maps.newHashMap();
            map.put("account",ACCOUNT);
            map.put("password",PASSWORD);
            String result = HttpUtil.post(IflytekConfig.BASE_URL + "/commonApi/user/login", JSON.toJSONString(map));
            if (StrUtil.isNotBlank(result)){
                JSONObject res = JSON.parseObject(result);
                if(IflytekConfig.UPLOAD_SUCCESS_CODE.equals(res.getString("retcode"))) {
                    return res.getString("accessToken");
                }
            }
            return "";
        });
    }

}
